package com.edgar.download;

import android.net.Uri;
import android.text.TextUtils;

import java.util.List;
import java.util.Locale;

/**
 * Created by xiexiang on 2015/11/1.
 */
public class Help {

    public static String getUriLastSegment(String strUri){
        if(TextUtils.isEmpty(strUri)){
            return "";
        }
        Uri uri = Uri.parse(strUri);
        List<String> pathSegments = uri.getPathSegments();
        if(pathSegments == null) return "";
        int size = pathSegments.size();
        if(size > 0){
            return pathSegments.get(size-1);
        }
        return uri.getAuthority();
    }

    public static String normalizeMimeType(String type) {
        if (type == null) {
            return null;
        }

        type = type.trim().toLowerCase(Locale.ROOT);

        final int semicolonIndex = type.indexOf(';');
        if (semicolonIndex != -1) {
            type = type.substring(0, semicolonIndex);
        }
        return type;
    }

}